package com.ftg.learn.chapter03.manyarray;

import java.util.Arrays;

/**
 * 十字相加
 *
 * @author 布衣
 */
public class TenSum {

    //分治  :
    //arr[] ,row = 0 col=0;
    public static int sum(int[][] arr, int row, int col) {

        int maxRow = arr.length - 1;
        int maxCol = arr[0].length - 1;
        int sum = 0;
        if (row - 1 >= 0) {
            sum += arr[row - 1][col];
        }
        if (row + 1 <= maxRow) {
            sum += arr[row + 1][col];
        }
        if (col - 1 >= 0) {
            sum += arr[row][col - 1];
        }
        if (col + 1 <= maxCol) {
            sum += arr[row][col + 1];
        }
        return arr[row][col] + sum;
    }

    public static int[][] penSum(int[][] arr){
        int[][] newArr = new int[arr.length][arr[0].length];
        for (int i = 0; i < arr.length; i++) {
            for (int i1 = 0; i1 < arr[i].length; i1++) {
                newArr[i][i1] = sum(arr,i,i1);
            }
        }
        return newArr;
    }

    public static int[] abc(int[] x){
        x[0] = 123;
        return x;
    }

    public static void main(String[] args) {
        int[][] arr = new int[][]{{1, 4, 7, 10, 13}, {2, 5, 8, 11, 14}, {3, 6, 9, 12, 15}};
        int x[] = {14,0};
        abc(x);
        System.out.println(x);
        System.out.println(Arrays.toString(x));
    }
//[1, 4, 7, 10, 13]
//[2, 5, 8, 11, 14]
//[3, 6, 9, 12, 15]

//    第一题  ： o(1)
//    力扣  ：  48|11|55
//    班级群里面的pdf 关于线性表的问题

}
